package com.ruoyi.web.controller.market.extend;

import java.util.List;
import java.util.Map;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.db.domain.PageTypeInfo;
import com.ruoyi.extend.service.IPageTypeInfoService;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.web.wapper.PageTypeInfoWapper;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 落地页类型Controller
 * 
 * @author ruoyi
 * @date 2022-08-11
 */
@Controller
@RequestMapping("/extend/page")
public class PageTypeInfoController extends BaseController
{
    private String prefix = "extend/page";

    @Autowired
    private IPageTypeInfoService pageTypeInfoService;

    @RequiresPermissions("extend:page:view")
    @GetMapping()
    public String page()
    {
        return prefix + "/page";
    }

    /**
     * 查询落地页类型列表
     */
    @RequiresPermissions("extend:page:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(PageTypeInfo pageTypeInfo)
    {
        startPage();
        List<Map<String, Object>> mapList = pageTypeInfoService.selectPageTypeInfoListMap(pageTypeInfo);
        mapList = new PageTypeInfoWapper(mapList).wrap();
        return getDataTable(mapList);
    }

    /**
     * 导出落地页类型列表
     */
    @RequiresPermissions("extend:page:export")
    @Log(title = "落地页类型", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(PageTypeInfo pageTypeInfo)
    {
        List<PageTypeInfo> list = pageTypeInfoService.selectPageTypeInfoList(pageTypeInfo);
        ExcelUtil<PageTypeInfo> util = new ExcelUtil<PageTypeInfo>(PageTypeInfo.class);
        return util.exportExcel(list, "落地页类型数据");
    }

    /**
     * 新增落地页类型
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存落地页类型
     */
    @RequiresPermissions("extend:page:add")
    @Log(title = "落地页类型", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(PageTypeInfo pageTypeInfo)
    {
        return toAjax(pageTypeInfoService.insertPageTypeInfo(pageTypeInfo));
    }

    /**
     * 修改落地页类型
     */
    @RequiresPermissions("extend:page:edit")
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") String id, ModelMap mmap)
    {
        PageTypeInfo pageTypeInfo = pageTypeInfoService.selectPageTypeInfoById(id);
        mmap.put("pageTypeInfo", pageTypeInfo);
        return prefix + "/edit";
    }

    /**
     * 修改保存落地页类型
     */
    @RequiresPermissions("extend:page:edit")
    @Log(title = "落地页类型", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(PageTypeInfo pageTypeInfo)
    {
        return toAjax(pageTypeInfoService.updatePageTypeInfo(pageTypeInfo));
    }

    /**
     * 删除落地页类型
     */
    @RequiresPermissions("extend:page:remove")
    @Log(title = "落地页类型", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(pageTypeInfoService.deletePageTypeInfoByIds(ids));
    }
}
